import React from 'react';
import { Button, Space } from 'antd-mobile';
import { getRiderInfo, isLoggedIn, isRiderActive, logout } from '../utils/auth';

function TestLogin() {
    const riderInfo = getRiderInfo();

    const handleLogout = () => {
        logout();
        window.location.reload();
    };

    return (
        <div style={{ padding: '20px' }}>
            <h2>登录状态测试</h2>
            
            <div style={{ marginBottom: '20px' }}>
                <p><strong>是否已登录:</strong> {isLoggedIn() ? '是' : '否'}</p>
                <p><strong>是否激活:</strong> {isRiderActive() ? '是' : '否'}</p>
            </div>

            {riderInfo && (
                <div style={{ marginBottom: '20px', padding: '10px', border: '1px solid #ccc', borderRadius: '8px' }}>
                    <h3>骑手信息:</h3>
                    <p><strong>姓名:</strong> {riderInfo.name}</p>
                    <p><strong>手机号:</strong> {riderInfo.phone}</p>
                    <p><strong>状态:</strong> {riderInfo.status}</p>
                    <p><strong>评分:</strong> {riderInfo.rating}</p>
                    <p><strong>注册时间:</strong> {new Date(riderInfo.createTime).toLocaleString()}</p>
                </div>
            )}

            <Space direction="vertical" block>
                <Button 
                    color="primary" 
                    onClick={() => window.location.href = '/login'}
                >
                    去登录
                </Button>
                
                {isLoggedIn() && (
                    <Button 
                        color="danger" 
                        onClick={handleLogout}
                    >
                        退出登录
                    </Button>
                )}
            </Space>
        </div>
    );
}

export default TestLogin; 